package com.jprocms.module.cms.convert.channel;

import com.jprocms.module.cms.controller.admin.channel.dto.ChannelRuleSourceDto;
import com.jprocms.module.cms.dal.dataobject.channel.ChannelRuleMapDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 栏目规则映射 Convert
 *
 * @author jprocms
 */
@Mapper
public interface ChannelRuleMapConvert {

    ChannelRuleMapConvert INSTANCE = Mappers.getMapper(ChannelRuleMapConvert.class);

    List<ChannelRuleMapDO> convertList(List<ChannelRuleSourceDto> list);

    default List<ChannelRuleMapDO> convertList(List<ChannelRuleSourceDto> list, Long targetChannelId) {
        List<ChannelRuleMapDO> ruleMapDOS = convertList(list);
        for (ChannelRuleMapDO ruleMapDO : ruleMapDOS) {
            ruleMapDO.setTargetId(targetChannelId);
        }
        return ruleMapDOS;
    }

}
